package aad.storyboard.view;

import android.content.Context;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.SurfaceView;
import android.util.AttributeSet;
import java.util.ArrayList;

public class ControlView extends SurfaceView {
	
	private ArrayList <TouchListener> listeners=new ArrayList<TouchListener>();
	
	public ControlView(Context context,	AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (event.getAction()==MotionEvent.ACTION_UP) {
			gestureListener.onSingleTapUp(event);
		}

		return(true);
	}

	public void addTapListener(TouchListener l) {
		listeners.add(l);
	}

	public void removeTapListener(TouchListener l) {
		listeners.remove(l);
	}

	private GestureDetector.SimpleOnGestureListener gestureListener=
		new GestureDetector.SimpleOnGestureListener() {
		@Override
		public boolean onSingleTapUp(MotionEvent e) {
			for (TouchListener l : listeners) {
				l.onTap(e);
			}

			return(true);
		}
	};

	public interface TouchListener {
		void onTap(MotionEvent event);
	}
}